package com.wrater.zero.common.mybatis;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class MyMetaObjectHander implements MetaObjectHandler {

//    @Override
//    public void insertFill(MetaObject metaObject) {
//        System.out.println("insert ing");
//        if(metaObject.hasSetter("createTime")) {
//            setInsertFieldValByName("createTime", LocalDateTime.now(), metaObject);
////            setInsertFieldValByName("createTime", LocalDateTime.now(), metaObject);
//            setInsertFieldValByName("managerId", 1087982257332887553L, metaObject);
//        }
//    }

    @Override
    public void insertFill(MetaObject metaObject) {
        System.out.println(" ==> start insert fill ....");
//        log.warn(" ==> start insert fill ....");

        this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, LocalDateTime.now());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        System.out.println(" ==> start update fill ....");
        this.strictUpdateFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());
    }

//    @Override
//    public void updateFill(MetaObject metaObject) {
//        System.out.println("update ing");
//        Object val = getFieldValByName("updateTime", metaObject);
//        if(val == null){
//            setUpdateFieldValByName("updateTime", LocalDateTime.now(), metaObject);
//
//        }
//    }
}
